package guoanmaker.operator.business.service;

import guoanmaker.operator.business.model.OperatorCities;
import guoanmaker.operator.business.repository.OperatorCitiesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.transaction.Transactional;

/**
 *  
 *
 * @ClassName: OperatorCitiesService 
 * @Description: OperatorCitiesService 
 * @author: huZhaoyu 
 * @date 2017/6/28 下午2:56 
 */
@Service
public class OperatorCitiesService implements OperatorCitiesServiceInterface {
    private final OperatorCitiesRepository operatorCitiesRepository;

    @Override
    public Integer countAllById() {
        return operatorCitiesRepository.countAllByIdIsNotNull();
    }

    @Autowired
    public OperatorCitiesService(OperatorCitiesRepository operatorCitiesRepository) {
        this.operatorCitiesRepository = operatorCitiesRepository;
    }

    @Override
    @Transactional
    public OperatorCities saveCities(OperatorCities operatorCities) {
        return operatorCitiesRepository.save(operatorCities);
    }

    @Override
    public List<OperatorCities> getAllCities() {
        return operatorCitiesRepository.findAll();
    }

    @Override
    public Page<OperatorCities> getAllCitiesByPage(Integer page, Integer size) {
        return operatorCitiesRepository.findAll(new PageRequest(page, size));
    }

    @Override
    @Transactional
    public void deleteCitiesById(String id) {
        operatorCitiesRepository.delete(id);
    }

    @Override
    public OperatorCities getCitiesById(String id) {
        return operatorCitiesRepository.findOne(id);
    }

    @Override
    public List<OperatorCities> getAllCitiesByProvinceCode(String provinceCode) {
        return operatorCitiesRepository.findAllByProvinceCode(provinceCode);
    }
    
    @Override
    public OperatorCities getCitiesByCode(String code) {
        return operatorCitiesRepository.findByCode(code);
    }
}
